
/**
 * 
 */

import java.io.File;
import java.io.IOException;

/**
 * 批量转换 input output
 * 
 * @author yuqinyi
 *
 */
public class PX2SIZE480B {

    private static final String SPLIT_KEY = "input";

    public static void main(String[] args) {
        try {
            File di = new File(new File("").getCanonicalPath() + "/input");
//            if (di.isDirectory()) {
//                for (int i = 0; i < di.list().length; i++) {
//                    PX2SIZEUtils.convert(di.list()[i]);
//                    System.out.println("file is ==>>" + di.list()[i]);
//                }
//            }
            isDirectory(di);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void isDirectory(File file) throws IOException {
        if (file.exists()) {
            if (file.isFile()) {
//                System.out.println("file's path is          ==>>" + file.getPath());
                System.out.println("file's CanonicalPath is ==>>" + file.getCanonicalPath());
//                System.out.println("file's CurrentPath is ==>>" + file.getCanonicalPath().split(SPLIT_KEY)[1]);
//                System.out.println("file's name is          ==>>" + file.getName());
                String fn2 = file.getCanonicalPath()
                        .substring(file.getCanonicalPath().indexOf(SPLIT_KEY) + SPLIT_KEY.length());
                System.out.println("fn2                     ==>>" + fn2);
                String[] fns = file.getCanonicalPath().split(SPLIT_KEY);
                if (fns != null && fns.length > 1 && fn2 != null && fn2.length() > 0) {
                    System.out.println("file's parentPath is    ==>>" + fns[0]);
                    System.out.println("file's nextPath is      ==>>" + fn2);
                    PX2SIZEUtils.convert(fn2);
                }
            } else {
                File[] list = file.listFiles();
                if (list.length == 0) {
                    System.out.println(file.getCanonicalPath() + " 下没有文件和文件夹！");
                } else {
                    for (int i = 0; i < list.length; i++) {
                        isDirectory(list[i]);
                    }
                }
            }
        } else {
            System.out.println("文件不存在！");
        }
    }

}
